import 'package:dio/dio.dart';

class HttpUtil {
  // 单例模式
  static HttpUtil? _instance;

  factory HttpUtil() => _getInstance()!;

  static HttpUtil? get instance => _getInstance();

  static HttpUtil? _getInstance() {
    _instance ??= HttpUtil._internal();
    return _instance;
  }

  HttpUtil._internal() {
    init();
  }

  late Dio _dio;
  late Dio _weatherDio;
  late Dio _serviceDio;

  // 初始化请求配置
  init() {
    _weatherDio = Dio(BaseOptions(
      baseUrl: "https://devapi.qweather.com",
      connectTimeout: const Duration(milliseconds: 3000),
    ));
    _serviceDio = Dio(BaseOptions(
      baseUrl: "http://81.70.250.171:48080/app-api",
      connectTimeout: const Duration(milliseconds: 3000),
    ));
    _dio = Dio();
  }

  getDio() => _dio;

  weatherDio() {
    return _weatherDio;
  }

  serviceDio() {
    return _serviceDio;
  }
}
